package cn.ctbu.xiaopeng.studentscoremanage.service;

import cn.ctbu.xiaopeng.studentscoremanage.anno.Log;
import cn.ctbu.xiaopeng.studentscoremanage.dao.TCRepository;
import cn.ctbu.xiaopeng.studentscoremanage.exception.ResultException;
import cn.ctbu.xiaopeng.studentscoremanage.pojo.dto.ScoreQueryDTO;
import cn.ctbu.xiaopeng.studentscoremanage.pojo.dto.TcQueryDTO;
import cn.ctbu.xiaopeng.studentscoremanage.pojo.entity.SC;
import cn.ctbu.xiaopeng.studentscoremanage.pojo.entity.TC;
import cn.ctbu.xiaopeng.studentscoremanage.pojo.vo.ScorePageVO;
import cn.ctbu.xiaopeng.studentscoremanage.pojo.vo.TcPageVO;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author xiaopeng
 * @version 1.0
 */
@Service
@RequiredArgsConstructor
public class TcService {
    private final TCRepository tcRepository;


    /**
     * 添加教师选课
     *
     * @param tc
     */
    @Log
    public TC insert(TC tc) {
        return tcRepository.save(tc);
    }


    /**
     * 修改教师选课信息
     *
     * @param tc
     */
    @Log
    public TC update(TC tc) {
        return tcRepository.save(tc);
    }

    /**
     * 删除教师选课
     *
     * @param id
     */
    @Log
    public void deleteById(Integer id) {
        tcRepository.deleteById(id);
    }

    /**
     * 根据id批量删除教师选课
     *
     * @param ids
     */
    @Log
    @Transactional
    public void deleteTCByIds(List<Integer> ids) {
        if (ids != null && !ids.isEmpty()) {
            tcRepository.deleteByIds(ids);
        } else {
            throw new ResultException("教师选课ID列表不能为空");
        }
    }

    /**
     * 分页查询
     *
     * @param pageable
     * @return
     */
    @Log
    public Page<TC> getAllWithPage(Pageable pageable) {
        return tcRepository.findAll(pageable);
    }

    /**
     * 根据条件查询教师选课信息
     *
     * @param tcQueryDTO
     * @param pageable
     * @return
     */
    @Log
    public Page<TcPageVO> getTcPageByConditions(TcQueryDTO tcQueryDTO, Pageable pageable) {
        return tcRepository.getTcPageByConditions(tcQueryDTO, pageable);
    }
}
